﻿using Files_Upload.Domain;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Files_Upload.Infrastructure
{
    public class ReportRepository : IReportRepository
    {
        private readonly MyDbcontext _context;

        public ReportRepository(MyDbcontext context)
        {
            _context = context;
        }

        // 获取所有报告
        public async Task<IEnumerable<Report>> GetAllReportsAsync()
        {
            return await _context.Reports.ToListAsync();
        }
        // 根据应用ID和文件名获取报告
        public async Task<Report> GetReportAsync(string appId, string fileName)
        {
            return await _context.Reports.FirstOrDefaultAsync(r => r.AppId == appId && r.FileName == fileName);
        }
        // 添加报告
        public async Task<int> AddReportAsync(Report report)
        {
            await _context.Reports.AddAsync(report);
           return  await _context.SaveChangesAsync();
        }
        // 更新报告
        public async Task<int> UpdateReportAsync(Report report)
        {
            _context.Reports.Update(report);
            return  await _context.SaveChangesAsync();
        }
    }
}
